package com.migu.contacts;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.fragment.app.Fragment;

import com.flyco.tablayout.listener.CustomTabEntity;
import com.frank.libandroid.BaseActivity;
import com.frank.libandroid.BottomPopup;
import com.frank.libandroid.DataStore;
import com.frank.libandroid.TabEntity;
import com.frank.libandroid.butterknife.OnClick;
import com.lxj.xpopup.XPopup;
import com.migu.contacts.bean.ContactBean;
import com.migu.contacts.databinding.ActivityMainBinding;
import com.migu.contacts.databinding.MainCraetePopBinding;
import com.migu.contacts.main.CalendarFragment;
import com.migu.contacts.main.ContactEditActivity;
import com.migu.contacts.main.CountDownFragment;
import com.migu.contacts.main.HomeFragment;
import com.migu.contacts.main.MyFragment;
import com.migu.contacts.main.ScanActivity;
import com.migu.contacts.main.create.ContactCreateActivity;

import java.util.ArrayList;

public class MainActivity extends BaseActivity<ActivityMainBinding> {
    @Override
    protected void initView() {
        super.initView();
        ArrayList<CustomTabEntity> tabEntityList = new ArrayList<>();
        tabEntityList.add(new TabEntity("首页", R.drawable.home_s, R.drawable.home));
        tabEntityList.add(new TabEntity("行事历", R.drawable.note_s, R.drawable.note));
        tabEntityList.add(new TabEntity("倒计时", R.drawable.time_s, R.drawable.time));
        tabEntityList.add(new TabEntity("我的", R.drawable.my_s, R.drawable.my));
        ArrayList<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(new HomeFragment());
        fragmentList.add(new CalendarFragment());
        fragmentList.add(new CountDownFragment());
        fragmentList.add(new MyFragment());
        mBinding.tabLayout.setTabData(tabEntityList, this, R.id.container, fragmentList);
        ViewGroup childAt = (ViewGroup) mBinding.tabLayout.getChildAt(0);
        View left = childAt.getChildAt(1);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) left.getLayoutParams();
        layoutParams.rightMargin = 200;
    }

    @Override
    public void onMessage(Object... value) {
        super.onMessage(value);
        Log.d(TAG, "onMessage() called with: value = [" + value + "]");
        create(null);
    }

    @Override
    protected void initData() {
        super.initData();
    }

    public void create(View view) {
        BottomPopup bottomPopup = new BottomPopup<MainCraetePopBinding>(this) {
            @OnClick(R.id.close)
            public void quit() {
                dismiss();
            }

            @OnClick(R.id.manual)
            public void manual() {
                DataStore.put(ContactEditActivity.CONTACT_BEAN_KEY, new ContactBean());
                start(ContactCreateActivity.class);
                dismiss();
            }

            @OnClick(R.id.auto)
            public void auto() {
                start(ScanActivity.class);
                dismiss();
            }
        };
        new XPopup.Builder(this).asCustom(bottomPopup).show();
    }

}